from django.http import HttpResponse
from rest_framework import serializers
from rest_framework.renderers import JSONRenderer

from outlines.models import Comment, SeceneMarkDesc


class CommentSerialize(serializers.ModelSerializer):
    mugshot_thumbnail = serializers.CharField(required=True)
    username = serializers.CharField(required=True)

    class Meta:
        model = Comment
        fields = ['content', 'add_time', 'mugshot_thumbnail', 'username']


class SeceneMarkDescSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = SeceneMarkDesc
        fields = ('content', 'add_time', 'secene', 'user', 'type')


class JSONResponse(HttpResponse):
    """
    用于返回JSON数据.
    """

    def __init__(self, data, **kwargs):
        content = JSONRenderer().render(data)
        kwargs['content_type'] = 'application/json'
        super(JSONResponse, self).__init__(content, **kwargs)
